#include "QyRenderItemList.h"
#include "QyRenderItemGeometry.h"

using namespace QyRender;

/**************************************************************************************************/

bool compareSerial( QyRender::Item * item, const QUuid & serial ) {

	return item->serial() == serial;
}

bool compareType( QyRender::Item * item, const quint32 & type ) {

	return item->type() == type;
}

bool checkPos( QyRender::Item * item, const QPointF & pos ) {

	return item->geometry().containsPoint( pos, Qt::OddEvenFill );
}

bool checkGeometry( QyRender::Item * item, const QyRender::ItemGeometry & geometry ) {

	return !item->geometry().intersected(geometry).isEmpty();
}

bool checkRect( QyRender::Item * item, const QRectF & rect ) {

	return checkGeometry( item, QyRender::ItemGeometry(rect) );
}

/**************************************************************************************************/

QyRender::Item * ItemList::item( const QUuid & serial ) const {

	ItemList items = findItem<QUuid>( *this, serial, compareSerial, FindSingleItem );

	return items.isEmpty() ? 0 : items.first();
}

QyRender::ItemList ItemList::items( quint32 type ) const {

	return findItem<quint32>( *this, type, compareType, FindAllItems );
}

QyRender::ItemList ItemList::collision( const QPointF & point ) const {

	return findItem<QPointF>( *this, point, checkPos, FindAllItems );
}

QyRender::ItemList ItemList::collision( const QRectF & rect ) const {

	return findItem<QRectF>( *this, rect, checkRect, FindAllItems );
}

QyRender::ItemList ItemList::collision( const QyRender::ItemGeometry & geometry ) const {

	return findItem<QyRender::ItemGeometry>( *this, geometry, checkGeometry, FindAllItems );
}


int test() { return 0; }
